/**
 * @copyright 2018 indie Semiconductor
 *
 * This file is proprietary to indie Semiconductor.
 * All rights reserved. Reproduction or distribution, in whole
 * or in part, is forbidden except by express written permission
 * of indie Semiconductor.
 *
 * @file pmua_sfr.h
 */

#ifndef __PMUA_SFR_H__
#define __PMUA_SFR_H__

#include <stdint.h>

/* -------  Start of section using anonymous unions and disabling warnings  ------- */
#if   defined (__CC_ARM)
  #pragma push
  #pragma anon_unions
#elif defined (__ICCARM__)
  #pragma language=extended
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  #pragma clang diagnostic push
  #pragma clang diagnostic ignored "-Wc11-extensions"
  #pragma clang diagnostic ignored "-Wreserved-id-macro"
#elif defined (__GNUC__)
  /* anonymous unions are enabled by default */
#elif defined (__TMS470__)
  /* anonymous unions are enabled by default */
#elif defined (__TASKING__)
  #pragma warning 586
#elif defined (__CSMC__)
  /* anonymous unions are enabled by default */
#else
  #warning Not supported compiler type
#endif

/**
 * @brief A structure to represent Special Function Registers for PMUA.
 */
typedef struct {

  union {
    struct {
      uint8_t  HIBERNATE                :  1;
      uint8_t  FASTBOOT                 :  1; /*!< Fast boot */
      uint8_t  FASTSHUTDOWN             :  1; /*!< Fast shutdown */
      uint8_t                           :  5; /*   (reserved) */
      uint32_t                          : 24; /*   (reserved) */
    };
    uint32_t WORD;
  } CTRL; /* +0x000 */

  uint8_t  IGNORE_CIFS;                       /*<! Ignore QACKs +0x004 */
  uint8_t  _RESERVED_05[3];                   /* +0x005 */

  union {
    struct {
      uint8_t  ENABLE_BIAS              :  4; /*!< Enable bias dwell time */
      uint8_t  ENABLE_1V8               :  4; /*!< Enable 1.8V dwell time */
      uint8_t  ATTACH_1V8               :  4; /*!< Attach 1.8V dwell time */
      uint8_t  ATTACH_2V6               :  4; /*!< Attach 2.6V dwell time */
      uint8_t  POWER_DOWN_MCU           :  4; /*!< Power down MCU dwell time */
      uint8_t  ENABLE_MAIN_REG          :  4; /*!< Enable main regulator dwell time */
      uint8_t                           :  8; /*   (reserved) */
    };
    uint32_t WORD;
  } DWELL; /* +0x008 */

  union {
    struct {
      uint8_t  UVMENA                   :  1; /*!< Battery Under Voltage Monitor Enable */
      uint8_t  OVMENA                   :  1; /*!< Battery Over Voltage Monitor Enable */
      uint8_t  UVPOL                    :  1; /*!< under voltage signal polarity */
      uint8_t  OVPOL                    :  1; /*!< over voltage signal polarity */
      uint8_t                           :  4; /*   (reserved) */
      uint8_t  UVLEVEL                  :  8; /*!< Battery Voltage Monitor Under Voltage Select */
      uint8_t  OVLEVEL                  :  8; /*!< Battery Voltage Monitor Over Voltage Select */
      uint8_t  UV                       :  1; /*!< Battery Voltage Low Status */
      uint8_t  OV                       :  1; /*!< Battery Voltage High Status */
      uint8_t                           :  6; /*   (reserved) */
    };
    uint32_t WORD;
  } VBATCTRL; /* +0x00C */

  union {
    struct {
      uint8_t  UV                       :  1; /*!< under voltage signal debounce enable */
      uint8_t  OV                       :  1; /*!< over voltage signal debounce enable */
      uint8_t  LFENA                    :  1; /*!< Low frequency strobing enable for debouncing */
      uint8_t                           :  5; /*   (reserved) */
      uint8_t  UVTHRES1                 :  3; /*!< Under Voltage debouncing threshold for 0to1 Transition */
      uint8_t                           :  1; /*   (reserved) */
      uint8_t  OVTHRES1                 :  3; /*!< Over Voltage debouncing threshold for 0to1 Transition */
      uint8_t                           :  1; /*   (reserved) */
      uint16_t                          : 16; /*   (reserved) */
    };
    uint32_t WORD;
  } VBATDBNC; /* +0x010 */

  union {
    struct {
      union {
        struct {
          uint8_t  UV                   :  1; /*!< under voltage interrupt enable */
          uint8_t  OV                   :  1; /*!< over voltage interrupt enable */
          uint8_t                       :  6; /*   (reserved) */
        };
        uint8_t BYTE;
      } ENABLE;
      union {
        struct {
          uint8_t  UV                   :  1; /*!< under voltage interrupt clear */
          uint8_t  OV                   :  1; /*!< over voltage interrupt clear */
          uint8_t                       :  6; /*   (reserved) */
        };
        uint8_t BYTE;
      } CLEAR;
      union {
        struct {
          uint8_t  UV                   :  1; /*!< under voltage interrupt status */
          uint8_t  OV                   :  1; /*!< over voltage interrupt status */
          uint8_t                       :  6; /*   (reserved) */
        };
        uint8_t BYTE;
      } STATUS;
      union {
        struct {
          uint8_t  UV                   :  1; /*!< under voltage interrupt active */
          uint8_t  OV                   :  1; /*!< over voltage interrupt active */
          uint8_t                       :  6; /*   (reserved) */
        };
        uint8_t BYTE;
      } IRQ;
    };
    uint32_t WORD;
  } VBATIRQ; /* +0x014 */

} PMUA_SFRS_t;

/* --------  End of section using anonymous unions and disabling warnings  -------- */
#if   defined (__CC_ARM)
  #pragma pop
#elif defined (__ICCARM__)
  /* leave anonymous unions enabled */
#elif (__ARMCC_VERSION >= 6010050)
  #pragma clang diagnostic pop
#elif defined (__GNUC__)
  /* anonymous unions are enabled by default */
#elif defined (__TMS470__)
  /* anonymous unions are enabled by default */
#elif defined (__TASKING__)
  #pragma warning restore
#elif defined (__CSMC__)
  /* anonymous unions are enabled by default */
#else
  #warning Not supported compiler type
#endif

/**
 * @brief The starting address of PMUA SFRS.
 */
#define PMUA_SFRS ((__IO PMUA_SFRS_t *)0x50000020)

#endif /* end of __PMUA_SFR_H__ section */


